﻿using Manon.Admin.Web.Application;
using Manon.Admin.Web.Application.Dtos.Role;
using Manon.Admin.Web.Application.Dtos.User;
using Manon.Core;
using Manon.Repository.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Manon.Admin.Web.Controllers
{
    public class UserController : Controller
    {
        private readonly IUserService _userService;
        private readonly IRoleService _roleService;
        public UserController(IUserService userService, IRoleService roleService)
        {
            _userService = userService;
            _roleService = roleService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Edit()
        {
            return View();
        }
        [Authorize]
        [HttpPost]
        public async Task<PagedList<UserOutput>> GetUserPageList([FromBody] GetUserPageListInput Input)
        {
            var result = await _userService.GetUserPageList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveUser([FromBody] SaveUserInput Input)
        {
            var result = await _userService.SaveUser(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<UserOutput> GetUser(int UserId)
        {
            var result = await _userService.GetUserById(UserId);
            return result;
        }


        [Authorize]
        [HttpPost]
        public async Task<Result> SetEnabled([FromBody] SetUserEnabledInput Input)
        {
            var result = await _userService.SetEnabled(Input);
            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> ModifyPassword([FromBody] ModifyPasswordInput Input)
        {
            var result = await _userService.ModifyPassword(Input);
            return result;
        }


        [Authorize]
        [HttpPost]
        public async Task<Result> BandUserRoles([FromBody] BandRoleInput Input)
        {
            var result = await _roleService.BandRoles(Input);

            return result;
        }

        [Authorize]
        [HttpGet]
        public async Task<List<string>> GetUserBandRoles(int UserId)
        { 
            var result = await _roleService.GetUserBandRoles(UserId);
            return result;
        }


    }
}
